﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;
using System.DirectoryServices; 

namespace WebRSSBuilder.ASP
{
    public partial class ManageRoles : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
          
    
        }

        protected void ButtonAddRole_Click(object sender, EventArgs e)
        {
            if (!Roles.RoleExists(this.TextBoxRoleName.Text))
            {
                Roles.CreateRole(this.TextBoxRoleName.Text);
                this.LabelError.Visible = false;
                this.LabelDeleteError.Visible = false; 
                this.GridView1.DataBind(); 
            }
            else
            {
                this.LabelError.Visible = true; 
            }
        }

        protected void LinqDataSource1_Deleting(object sender, LinqDataSourceDeleteEventArgs e)
        {
            /*if (((aspnet_Role)e.OriginalObject).Files.Count > 0)
            {
                e.Cancel = true;
                this.LabelDeleteError.Visible = true;
                this.LabelError.Visible = false;
            }
            else
            {
                this.LabelError.Visible = false;
                this.LabelDeleteError.Visible = false; 
            }*/
        }

        protected void LinqDataSource1_Deleted(object sender, LinqDataSourceStatusEventArgs e)
        {
            if (e.Exception != null)
            {
                if (e.Exception is System.Data.SqlClient.SqlException)
                {
                    this.LabelDeleteError.Visible = true;
                    this.LabelError.Visible = false;
                    e.ExceptionHandled = true; 
                }
            }
            else
            {
                this.LabelError.Visible = false;
                this.LabelDeleteError.Visible = false; 
            }
        }

        
    }
}